import random
from time import time

# 随机数范围
M = 0
N = 50

def inNum():
    while (True):
        try:
            n = int(input(">>>"))
            break
        except ValueError as value_err:
            print("输入一个数字！")
            continue
    return n

def clear():
    print('\n\n\n\n\n\n\n\n\n\n\n\n')

def game_tip(str,gold):
    print("{tips}\t\t你还有{0}".format(gold,tips=str))

def game_main(num, gold):
    print("猜猜看~你面前这个铁壳笨蛋到底准备了个什么数字？")
    while(True):
        a = inNum()

        gold -= 500
        if (a < num):
            game_tip("小了", gold)
        elif (a > num):
            game_tip('大了', gold)
        else:
            gold += 3500
            print('哇哦！猜中了！就是{}！你现在有{}了！'.format(a, gold))
            return gold

        if (gold <= 0):
            print('没有钱钱了，唉~')
            return 0

def game():
    gold = 5000
    print("欢迎来到~人工智障擂台赛！")
    print("比赛规则很简单，人工智障会给出一个{}以内的整数，看看你能否猜中~".format(N))
    while True:
        print('告诉我你的选择！(输入数字)/ 1-参加比赛 2-退出比赛')
        choice = int(input(">>>>"))
        clear()
        if (choice == 1):
            print("我看好你哦~")
            gold = game_main(random.randint(M, N), gold)
            if (gold == 0):
                print("真是可惜，欢迎再来")
                break
        elif (choice == 2):
            print("真是可惜，欢迎再来")
            break
        else:
            print("也许你应该告诉我你的选择，而不是胡言乱语")





def even100():
    sum1 = 0
    for i in range(0,101,2):
        sum1 += i
    print (sum1)

def Bichromatic_sphere():
    print("机选几组号？")
    k = inNum()

    for i in range(k):
        Bs1 = random.sample(range(1, 33), k=6)
        Bs1.sort()
        while(True):
            seven = random.randint(1, 15)
            if (not seven in Bs1):
                break
        for i in Bs1:
            print(str(i).zfill(2), end='\t')
        print('|  {}'.format(str(seven).zfill(2)))

def everySeven():
    for i in range(0,101,1):
        if (i % 7 == 0 or i%10 == 7 or int(i/10) == 7 ):
            continue
        print(i)

def MT99():
    list = ['壹','贰','叁','肆','伍','陆','柒','捌','玖']
    print('\t', end='')
    for i in list:
        print(i, end='\t')
    print()
    for i in range(1, 10):
        print(list[i-1], end='\t')
        for j in range(1, 10):
            print(i*j, end='\t')
        print()

def F7A5():
    i = 0
    while(True):
        i += 1
        if(i%7 == 0 and i%5 != 0):
            print(i, end=',\t')

        if(i == 10000):
            break

def factorial():
    sum = 1
    print("让我们看看他的阶乘是多少？")
    k = inNum()
    while(k):
        sum *= k
        k -= 1
    print(sum)

def Fibonacci():
    print('菲波那切数列')

    n = inNum()

    Fib = [1, 1]
    for i in range(1, n):
        Fib.append(Fib[i]+Fib[i-1])
    print(Fib[n-1])

def primeNum():
    print("是否是质数？")
    k = inNum()

    for i in range(2, int(k/2+1)):
        if(k%i == 0):
            print("不是质数,案例：%d %d"%(i, k/i))
            return False
    print("居然是质数诶...")
    return True

def Bubble_Sort():
    list = []
    a = 1
    print("冒泡排序\t(停止输入数为-1)")
    while(True):
        a = inNum()
        if(a == -1):
            break
        list.append(a)

    for i in range(len(list)):
        for j in range(len(list)-i-1):
            if(list[j]>list[j+1]):
                list[j], list[j+1] = list[j+1], list[j]

    print(list)

# 界面
def UI():

    flag = 0
    t = time()

    print("你想干什么？")
    print("> 1 —— 猜数字")
    print("> 2 —— 100内偶数和")
    print("> 3 —— 双色球选号")
    print("> 4 —— 逢七")
    print("> 5 —— 九九乘法表")
    print("> 6 —— 友7敌5")
    print("> 7 —— 阶乘")
    print("> 8 —— 斐波那契数列")
    print("> 9 —— 质数")
    print("> 10 —— 冒泡排序")
    print('# 请输入上述数字，随后你懂得~')
    flag = input(">>")

    clear() #假装清屏
    switch.get(flag)()  # 执行对应的函数，如果没有就执行默认的函数
    print('\n——执行完成/所用时间:%fs' % (time() - t))
    input('---------按任意键继续......')

# 假借字典实现switch引索
switch = {
    '1' : game,                 # 猜数字
    '2' : even100,              # 100内偶数和
    '3' : Bichromatic_sphere,   # 双色球选号
    '4' : everySeven,           # 逢七
    '5' : MT99,                 # 九九乘法表
    '6' : F7A5,                 # 友7敌5
    '7' : factorial,            # 阶乘
    '8' : Fibonacci,            # 斐波那契数列
    '9' : primeNum,             # 质数
    '10' : Bubble_Sort,         # 冒泡排序
}

while True:
    UI()

